<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php
$sidebarM = $this->options->sidebarBlockM;  //  获取侧边栏的移动设备显示设置
if (!is_array($sidebarM)) {
    $sidebarM = array();
}
$hideClass = 'd-md-none d-sm-none d-none d-lg-block d-xl-block';  //  用于在移动设备上隐藏区块的class
?>
<div class="sidebar layui-col-md3 layui-col-lg3">
    <div class="component">
        <form class="layui-form" id="search" method="post" action="<?php $this->options->siteUrl(); ?>" role="search">
            <div class="layui-inline input">
                <input type="text" id="s" name="s" class="layui-input" required lay-verify="required" placeholder="<?php _e('输入关键字搜索'); ?>" />
            </div>
            <div class="layui-inline">
                <button class="layui-btn layui-btn-sm layui-btn-primary"><i class="layui-icon">&#xe615;</i></button>
            </div>
        </form>
    </div>
    <div class="column">
        <h3 class="title-sidebar"><i class="layui-icon">&#xe705;</i> <?php _e('栏目分类'); ?></h3>
        <ul class="layui-row layui-col-space5">
            <?php $this->widget('Widget_Metas_Category_List')
               ->parse('<li class="layui-col-md12 layui-col-xs6"><a href="{permalink}"><i class="layui-icon">&#xe63c;</i> {name}<span class="layui-badge layui-bg-gray">{count}</span></a></li>'); ?>
        </ul>
    </div>
    <div class="dynamic">
        <h3 class="title-sidebar"><i class="layui-icon">&#xe60c;</i>博主动态 ~ </h3>
        <ul>
            <?php
                $db = Typecho_Db::get();
                $cid = $db->fetchRow($db->select('cid')->from('table.contents')->where('template = ? AND status = ?', 'mylife.php', 'publish'))['cid'];
                $comments = $db->fetchAll($db->select()->from('table.comments')->where('cid = ? AND status = ?', $cid, 'approved')->order('created', Typecho_Db::SORT_DESC));
                
                foreach($comments as $comment) {
                    echo '<li>';
                    echo '<span class="layui-badge-dot layui-bg-gray"></span>';
                    echo '<p>'.$comment['text'].'<small>'.date("Y年m月d日 H:i:s",$comment['created']).'</small></p>';
                    echo '</li>';
                }
            ?>          
        </ul>
    </div>
    <div class="tags">
            <h3 class="title-sidebar"><i class="layui-icon">&#xe66e;</i>标签云</h3>
            <div>
                <?php $this->widget('Widget_Metas_Tag_Cloud', 'ignoreZeroCount=1&limit=30')->to($tags); ?>
                <?php while($tags->next()): ?>
                    <a class="layui-btn layui-btn-xs layui-btn-primary" style="color: rgb(<?php echo(rand(0, 255)); ?>, <?php echo(rand(0,255)); ?>, <?php echo(rand(0, 255)); ?>)" href="<?php $tags->permalink(); ?>" title='<?php $tags->name(); ?>'><?php $tags->name(); ?></a>
                <?php endwhile; ?>
            </div>
    </div>

    <?php if ($this->options->links or $this->options->homeLinks && $this->is('index')): ?>
        <div class="link">
            <h3 class="title-sidebar"><i class="layui-icon">&#xe64c;</i>友情链接<a style="float: right;color: #666;" href="link.html">申请</a></h3>
            <div>
                <section class="<?php echo in_array('HideLinks', $sidebarM)?$hideClass:''; ?>">
                        <?php if ($this->options->homeLinks && $this->is('index')): ?>
                            <?php $homeLinks = json_decode($this->options->homeLinks); ?>
                            <?php foreach ($homeLinks as $val): ?>
                                <a class="layui-btn layui-btn-xs layui-btn-primary" href="<?php echo $val->url; ?>" title='<?php echo isset($val->title)?$val->title:'暂无简介'; ?>' target="_blank"><?php echo $val->name; ?></a>
                            <?php endforeach; ?>
                        <?php endif; ?>
                        <?php if ($this->options->links && !$this->is('index')): ?>
                            <?php $links = json_decode($this->options->links); ?>
                            <?php foreach ($links as $val): ?>
                                <a class="layui-btn layui-btn-xs layui-btn-primary" href="<?php echo $val->url; ?>" title='<?php echo isset($val->title)?$val->title:'暂无简介'; ?>' target="_blank"><?php echo $val->name; ?></a>
                            <?php endforeach;; ?>
                        <?php endif; ?>
                </section>
            </div>
        </div>
    <?php endif; ?>
</div>